package zeno.project.springboot.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

/**
 * 使用ServletRequestListener获取访问信息
 * @author shengwu ni
 * @date 2018/07/05
 */
@Component
public class MyServletRequestListener implements ServletRequestListener {

    private static final Logger logger = LoggerFactory.getLogger(MyServletRequestListener.class);

    /**
     * 新来请求时
     * @param servletRequestEvent 可获得request中的参数，sessionId、url等，且可增强添加一些参数到请求中
     */
    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
    }

    /**
     * 请求结束销毁时
     * @param servletRequestEvent 可获得request域中保存的值
     */
    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        logger.info("request end");
    }
}
